/**
 *Created by Pound on 19/7/15.
 * @desc 大屏控制器，用于各个组件跳转、弹出等；部分通用函数
 */
import globalVariable from "@/api/global_variable.js";
import transWGS from "@/utils/transWGS.js";
import ReconnectingWebSocket from "reconnecting-websocket";
import {
  Loading,
  Message
} from "element-ui";
import {
  logout
} from "@/api/api";
import {
  initGisInfo,
  init3dData /* , getMapSceneType */
} from "@/api/gis";
import {
  getMarkDetail
} from "@/api/markInfo3d";
import {
  getVideoByIds
} from "@/api/video";
import {
  getBsMarkInfo
} from "@/api/detectorMonitor";
let Base64 = require("js-base64").Base64;

/* 所有页面跳转事件写到控制器中，方便有三维存在的时候能使用同一套逻辑 */
/* @返回多单位首页 */
function backHome(lastMapType, isForceed = true) {
  // 详情大页面隐藏
  // 子页面隐藏（左右）（为空判断）
  // 单单位首页隐藏（左右）；
  // 多单位首页显示（左右）；
  // 假如已经在多单位首页了
  // 三维/二维地图飞到默认中心点
  //重新初始化地图
  if (!topVue.bsConfig.MapOptions.svgMap)
    loading(1, 1000);
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  let isUnityMap = localStorage.getItem("ilinkBs_defultMapType") == 4;
  let isMuilUnitUser = topVue.$store.state.userInfo.isMuilUnitUser //0:单单位用户;1:多单位用户
  topVue.$store.commit('setCurrentInspectId', '') ////初始化日巡检任务id
  topVue.$store.commit('setCurrentOrgId', isMuilUnitUser ? '' : topVue.$store.state.userInfo.org.id)
  topVue.$store.commit('setCurrentBuildId', '')
  topVue.$store.commit('setCurrentFloorId', '')
  // 初始化缓存中的路由数组
  initRouteList();
  if (isCs(true)) {
    // 关闭详情页
    topVue.$Cs.closeDetailsPage(0);
    topVue.$Cs.openRelatedPages(10401, "1", "");
    topVue.$Cs.openRelatedPages(10402, "1", "");
    topVue.$Cs.markersShowCtrl("22,33", 1);
    topVue.$Cs.markersShowCtrl("32,34", 2);
    if (localStorage.getItem('Build_Top') != 2) { // 报警数
      topVue.$Cs.markersShowCtrl("92", 1);
      topVue.$Cs.markersShowCtrl("51", 2);
    } else { // 设备正常率
      topVue.$Cs.markersShowCtrl("51", 1);
      topVue.$Cs.markersShowCtrl("92", 2);
    }
    topVue.$Cs.tooltype3d(6);
  } else {
    if (topVue.bsConfig.MapOptions.svgMap) {
      window.ZHXF_RESET_SVG_MAP()
    } else if (isUnityMap && isForceed) {
      window.FunList.initMap(4);
    } else if (mapType == 1) {
      window.FunList.initMap(mapType);
    } else if (mapType == 2) {
      initGisInfo({
        bizId: topVue.$store.state.userInfo.org.id,
        type: 2,
        idType: topVue.$store.state.userInfo.isMuilUnitUser ? 0 : 1
      }).then((res) => {
        if (res.data) {
          if (!res.data.gisInfo && isForceed) {
            window.FunList.initMap(1);
          } else {
            window.FunList.initMap(mapType);
          }
        }
      })
    } else if (mapType == 4) {
      window.FunList.initMap(mapType);
    }
    window.FunList.closeCommonDialog && window.FunList.closeCommonDialog()
    // 关闭详情页
    window.FunList.changeDetailModelShow(false);
    //左边回到首页
    window.FunList.changeLeftModelShow(1);
    //右边回到首页
    window.FunList.changeRightModelShow(1);
  }
  //关闭工具箱
  closePopup("ToolsMap");
  //关闭系统设置
  closePopup("WebsocketSet");
  changePageSize(2);
}
/* @进入单单位首页 
    fixToOrg  是否需要定位到该单位首页
*/
function enterSingleHome(param, fixToOrg, callback, isCacheRoute = true) {
  changePageSize(2);
  if (!param.orgId) {
    //如果是单单位用户
    param.orgId = topVue.$store.state.userInfo.organizationIds;
  }
  localStorage.setItem("ilinkBs_orgIds", param.orgId);
  topVue.$store.commit('setCurrentOrgId', param.orgId);
  topVue.$store.commit('setCurrentBuildId', '');
  topVue.$store.commit('setCurrentFloorId', '');
  // 记录到缓存中的路由数组
  if (isCacheRoute)
    addRoutePage("SingleHome", param);
  // 详情大页面隐藏（为空判断）
  // 子页面隐藏（左右）（为空判断）
  // 多单位首页隐藏（左右）；
  // 单单位首页显示（左右）；；
  // 假如已经在单单位首页了
  // 三维/二维地图飞到单位中心点
  //重新初始化地图
  // 传 type=0 ，重新获取地图类型
  // 获取刚单位的默认地图类型
  loading(1, 2000);
  initGisInfo({
    bizId: param.orgId,
    type: 0
  }).then(re => {
    let mapType = localStorage.getItem("ilinkBs_currentMapType");
    let gisInfo = "";
    if (re.data && re.data.gisInfo) {
      gisInfo = re.data.gisInfo;
      mapType = re.data.type;
    }
    if (isCs(true)) {
      // 关闭详情页
      topVue.$Cs.closeDetailsPage(0);
      topVue.$Cs.openRelatedPages(10401, "2", JSON.stringify(param));
      topVue.$Cs.openRelatedPages(10402, "2", JSON.stringify(param));
      topVue.$Cs.markersShowCtrl("22,33,34", 1);
      topVue.$Cs.markersShowCtrl("32", 2);
      if (localStorage.getItem('Build_Top') != 2) { // 报警数
        topVue.$Cs.markersShowCtrl("92", 1);
        topVue.$Cs.markersShowCtrl("51", 2);
      } else { // 设备正常率
        topVue.$Cs.markersShowCtrl("51", 1);
        topVue.$Cs.markersShowCtrl("92", 2);
      }
    } else {
      loading(0)
      if (topVue.bsConfig.MapOptions.svgMap) {
        window.ZHXF_FOCUS_UNIT_MAP(param.orgId)
      } else if (mapType == 1 || mapType == 2 || mapType == 4) {
        setMapOptions(
          param.orgId,
          mapType,
          () => {
            refreshMapMarkerDataToFmap();
            callback && callback()
          },
          1,
          gisInfo
        );
      }
      // 关闭详情页
      window.FunList.changeDetailModelShow(false);
      if (param && param.isRefresh) {
        if (!param.lastPageName || (param.lastPageName == 'SingleHome' || param.lastPageName == 'Home')) {
          window.FunList.changeLeftModelShow(2, param);
          window.FunList.changeRightModelShow(2, param);
        } else {
          enterChild(param.lastPageName, {
            orgIds: param.orgId,
            ...param
          })
        }
      } else {
        window.FunList.changeLeftModelShow(2, param);
        window.FunList.changeRightModelShow(2, param);
      }
    }

    //关闭工具箱
    closePopup("ToolsMap");
    //关闭系统设置
    closePopup("WebsocketSet");
  });
}
/**
 *切换单单位地图
 */
function enterSingleUnitMap(param, callback, afterSetMark) {
  if (topVue.$store.state.currentMapType == 4) {
    topVue.$store.commit('setCurrentMapType', 2)
  }
  topVue.$store.commit('setCurrentOrgId', param.orgId)
  localStorage.setItem("ilinkBs_orgIds", param.orgId);
  loading(1, 2000);
  initGisInfo({
    bizId: param.orgId,
    type: 0
  }).then(re => {
    let mapType = topVue.$store.state.currentMapType;
    let gisInfo = "";
    if (re.data && re.data.gisInfo) {
      gisInfo = re.data.gisInfo;
      mapType = re.data.type;
    }
    loading(0)
    if (mapType == 1 || mapType == 2 || mapType == 4) {
      setMapOptions(
        param.orgId,
        mapType,
        () => {
          refreshMapMarkerDataToFmap(afterSetMark);
          callback && callback()
        },
        1,
        gisInfo
      );
    }
  });
}
/* @进入左右结构的子页面 
pageName:
    设备一张图: 'MapEquipment'
    接处警: 'ReceivingPolice'
    巡检: 'Inspection'
    隐患整改-总览: 'RectificationDangers'
    消防维保: 'Maintenance'
    呼叫中心: 'CellCenter'  只显示左侧一边
rightOrLeft:
    左边联动右边，做特殊处理
*/
function enterChild(pageName, param, rightOrLeft) {
  param.pageName = pageName;
  if (isCs(true)) {
    if (!rightOrLeft) {
      // 关闭详情页
      topVue.$Cs.closeDetailsPage(0);
      topVue.$Cs.markersShowCtrl("22,32,33,34,51,92", 1);
      // 记录到缓存中的路由数组
      addRoutePage(pageName, param);
      topVue.$Cs.openRelatedPages(10401, "3", JSON.stringify(param));
      if (pageName == "CellCenter") {
        topVue.$Cs.closeDetailsPage(10402);
      } else {
        // 显示地图上的按钮，进入全屏详情页
        if (pageName == "RectificationDangers") {
          topVue.$Cs.markersShowCtrl("32", 2);
        }
        topVue.$Cs.openRelatedPages(10402, "3", JSON.stringify(param));
      }
    } else if (rightOrLeft == "right" && pageName == "MapEquipment") {
      topVue.$Cs.openRelatedPages(
        10402,
        "MapEquipment",
        JSON.stringify(param)
      );
    } else if (rightOrLeft == "right" && pageName == "Inspection") {
      /* else if(rightOrLeft=="left" && pageName =='MapEquipment'){
                  topVue.$Cs.openRelatedPages(10401,'MapEquipment',JSON.stringify(param))
              } */
      topVue.$Cs.openRelatedPages(
        10402,
        "Inspection",
        JSON.stringify(param)
      );
    } else if (rightOrLeft == "right" && pageName == "Maintenance") {
      topVue.$Cs.openRelatedPages(
        10402,
        "Maintenance",
        JSON.stringify(param)
      );
    }
  } else {
    // 关闭详情页
    window.FunList.changeDetailModelShow(false);
    if (!rightOrLeft) {
      // 记录到缓存中的路由数组
      addRoutePage(pageName, param);
      window.FunList.changeLeftModelShow(3, param);
      if (pageName == "CellCenter") {
        window.FunList.changeRightModelShow("CellCenter", param);
      } else {
        window.FunList.changeRightModelShow(3, param);
      }
    } else if (rightOrLeft == "right" && pageName == "MapEquipment") {
      if (window.FunList.changeRightModel_MapEquipmentRight) {
        window.FunList.changeRightModel_MapEquipmentRight(param);
      } else {
        // 有可能是设备详情【定位】>设备一张图
        window.FunList.refreshChidRight(param)
      }
    } else if (rightOrLeft == "right" && pageName == "Inspection") {
      window.FunList.changeRightModel_InspectionRight(param);
    } else if (rightOrLeft == "right" && pageName == "Maintenance") {
      window.FunList.changeRightModel_MaintainRight(param);
    }
    //显示切换隐患详情的按钮
    let markData = [];
    if (localStorage.getItem("ilinkBs_mapData")) {
      markData = JSON.parse(localStorage.getItem("ilinkBs_mapData"));
    }
    if (pageName == "RectificationDangers") {
      //地图隐患打点
      let hiddenArr = [];
      if (markData && markData.hidden && markData.hidden[0]) {
        hiddenArr = markData.hidden[0].data;
      }
      setMapMark({
          32: hiddenArr
        },
        true,
        false
      );
    } else if (pageName == "ReceivingPolice") {
      //地图接处警打点
      let modelStatusArr = {};
      $.each(markData.modelStatus, (index, obj) => {
        modelStatusArr[obj.type] = obj.data;
      });
      $.each(markData.top, (index, obj) => {
        if (obj.type === 51) {
          modelStatusArr[obj.type] = obj.data;
        }
      });
      setMapMark(modelStatusArr, true, false);
    } else if (pageName == "Maintenance") {
      //地图维保打点
      // let maintenanceArr = []
      // if(markData && markData.maintenance &&  markData.maintenance[0]){
      //     maintenanceArr = markData.maintenance[0].data
      // }
      // setMapMark( {33:maintenanceArr}, true, false)
    } else if (pageName == "MapEquipment") {
      //设备一张图
      setMapMark({}, true, false);
    }
  }

  changePageSize(1);

  // CS端显示地图上的按钮，进入全屏详情页
  if (isCs(true)) {
    setTimeout(() => {
      if (pageName == "RectificationDangers") {
        topVue.$Cs.disPlayBut(1);
      } else if (pageName == "Maintenance") {
        topVue.$Cs.disPlayBut(2);
      }
    }, 200);
  }
}
/* @进入全屏的详情页 */
/*
* 初始化详情页的方法
* 【参数说明】：
 pageName  详情页展示的模块名称
        安全评估: 'FireSafetyAssess'
        高危信号:  'HighRiskSignal'
        重大问题:  'ImportQuestion'
        平台管理:  'PlatformManage'
        设备清单:  'EquipmentList'
        隐患整改-清单: 'HiddenDangers'
        AI云视: 'AICloudVideo'
        消防维保-时间线 'MaintenanceTimeLine'
 param  页面传递的参数
*/
function enterDetail(pageName, param) {
  // 记录到缓存中的路由数组
  addRoutePage(pageName, param);
  if (isCs(true)) {
    // 关闭详情页
    topVue.$Cs.closeDetailsPage(0);
    topVue.$Cs.openRelatedPages(10001, pageName, JSON.stringify(param));
    topVue.$Cs.markersShowCtrl("22,32,33,34,51,92", 1);
    if (pageName == "HiddenDangers") {
      topVue.$Cs.markersShowCtrl("32", 2);
    }
  } else {
    // 关闭弹框
    window.FunList.closeCommonDialog && window.FunList.closeCommonDialog();
    window.FunList.changeDetailModelShow(true, pageName, param);
  }

  changePageSize(2);
}
/* @打开小弹窗（地图上的弹窗） */
/*1. 100**详情全页面
     10000:登录+loading+首页
     10001:高危信号等
2. 101**详情小弹框
     10100:设备详情等
     10101:三维导航
     10104:天气气象站
     10105:天气小页面
     10107:接受到报警跑马灯
     10116:预案处理详情
     10118:消防车详情
3. 102**子页面左(和首页公用左，为了减少CS端页面)
     10200:设备列表
     10201:维保左
     10202:接处警左
     10203:隐患左
     10204:巡检左
4. 103**子页面右(和首页公用右，为了减少CS端页面)
     10301:维保右
     10302:接处警右
     10303:隐患右
     10304:巡检右
5. 104**首页面
     10400:首页底部地图
     10401:多/单位左
     10402:多/单位右
     10403:多/单位下
6. 106**三维自绘框
     10600:系统加载loading页
     10601:测试中窗口
     10602:点击间隔提示框
     10603:系统错误提示框
     10604:关闭系统确认框
     10605:三维切换确认框
     10606:巡检路线图例
7. 107**按钮
     10700:三维工具框
     10701:热力图按钮
     10702:自动跟随按钮
     10703:清单试图按钮
     10704:隐患热力图按钮
     10705:时间试图按钮
     10706:二三维切换按钮
*/
// 打开设备物联小弹框
// window.FunList.openCommonDialog('DeviceDetails', {id: 1})
// 打开隐患整改弹框
// window.FunList.openCommonDialog('HiddenDanger', {id: 251})
// 打开巡检点位弹框
// window.FunList.openCommonDialog('PatrolPoint', {id: 251})
// 打开周边设备小弹框
//window.FunList.openCommonDialog('Peripherals', {a:xxxx,b:xxxxx})
// 打开导航小弹框
// window.FunList.openCommonDialog('Navigation', { a:xxxx,b:xxxxx })
// 打开消防车详情弹窗 TODO
// window.FunList.openCommonDialog('CarDetail', {id: 1})
// 打开音视频通话弹框
// window.FunList.openCommonDialog('DialNumber', {userName: '维保经理萧十一郎'})
// 打开推送设置
//window.FunList.openLeftDialog('WebsocketSet',{})
function openPopup(pageName, objId, objVal) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (isCs(true)) {
    //10101 导航二、三维是不同的百度地图导航界面
    // 关闭详情页
    //topVue.$Cs.closeDetailsPage(0)
    if (pageName == "WebsocketSet") {
      //推送设置
      window.FunList.openLeftDialog("WebsocketSet", {});
    } else if (pageName == "ToolsMap") {
      //地图工具包
      window.FunList.openLeftDialog(
        mapType == 1 ?
        "ToolsBaidu" :
        mapType == 2 ?
        "ToolsFmap" :
        "Tools3D", {}
      );
    } else if (pageName == "largeScreen") {
      // 大屏跳转到pc
      topVue.$Cs.openRelatedPages(
        10111,
        pageName,
        JSON.stringify(objVal)
      );
    } else if (pageName == "Navigation") {
      //导航 TODO
      objVal.location = ""; // 备注：复杂的数据结构CS端传递不了
      topVue.$Cs.openRelatedPages(
        10101,
        pageName,
        JSON.stringify(objVal)
      );
    } else if (pageName == "DeviceDetails") {
      // 公用常规探测器的弹窗
      topVue.$Cs.openRelatedPages(
        10100,
        pageName,
        JSON.stringify({
          id: objId
        })
      );
    } else if (pageName == "HiddenDanger") {
      // 隐患指派
      topVue.$Cs.openRelatedPages(
        10103,
        pageName,
        JSON.stringify({
          id: objId
        })
      );
    } else if (pageName == "PatrolPoint") {
      // 巡检点位
      topVue.$Cs.openRelatedPages(
        10102,
        pageName,
        JSON.stringify({
          id: objId
        })
      );
    } else if (pageName == "CarDetail") {
      // 消防车详情弹窗
      topVue.$Cs.openRelatedPages(
        10118,
        pageName,
        JSON.stringify({
          id: objId
        })
      );
    } else if (pageName == "DialNumber") {
      // 音视频通话弹框
      topVue.$Cs.openRelatedPages(
        10106,
        pageName,
        JSON.stringify(objVal)
      );
    } else if (pageName == "Peripherals") {
      // 周边设备
      objVal.location = ""; // 备注：复杂的数据结构CS端传递不了
      topVue.$Cs.openRelatedPages(
        10109,
        pageName,
        JSON.stringify(objVal)
      );
    } else {
      topVue.$Cs.openRelatedPages(
        10100,
        pageName,
        JSON.stringify(
          objVal ?
          objVal : {
            id: objId
          }
        )
      );
    }
  } else {
    if (pageName == "WebsocketSet") {
      //推送设置
      window.FunList.openLeftDialog("WebsocketSet", {});
    } else if (pageName == "ToolsMap") {
      //地图工具包
      window.FunList.openLeftDialog(
        mapType == 1 ?
        "ToolsBaidu" :
        mapType == 2 ?
        "ToolsFmap" :
        "Tools3D", {}
      );
    } else if (pageName == "largeScreen") {
      // 大屏跳转到pc
      topVue.$Cs.openRelatedPages(
        10111,
        pageName,
        JSON.stringify(objVal)
      );
    } else {
      // 公用常规探测器的弹窗（隐患指派、巡检点位、周边设备、导航、打电话、消防车等）
      // 关闭弹框
      window.FunList.closeCommonDialog &&
        window.FunList.closeCommonDialog();
      // 初始化弹框位置
      let dialogDom = document.querySelector(".popup-dialog");
      if (pageName == "CarDetail") {
        dialogDom.style.overflow = "hidden";
        dialogDom.style.top = "40%";
        dialogDom.style.height = "750px";
      } else {
        dialogDom.style.top = "50%";
        dialogDom.style.left = "50%";
        dialogDom.style.height = "600px";
      }
      window.FunList.openCommonDialog(
        pageName,
        objVal ?
        objVal : {
          id: objId
        }
      );
    }
  }
}
/* 关闭弹窗 */
function closePopup(pageName) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (pageName === "WebsocketSet") {
    //推送设置
    window.FunList.closeLeftDialog("WebsocketSet", {});
  } else if (pageName === "ToolsMap") {
    //地图工具包
    window.FunList.closeLeftDialog(
      mapType == 1 ? "ToolsBaidu" : mapType == 2 ? "ToolsFmap" : "Tools3D"
    );
  }
}
/* 根据标注id获取视频信息 
   三维中点击地图标注调取的这个函数
*/
function getVideoDetail(markId) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (topVue.$store.state.currentMapType == 4) mapType = 2 // 如果地图为unity地图 则将dtype强改为2
  getMarkDetail({
    id: markId,
    dType: mapType
  }).then(res => {
    let data = res.data.data;
    if (data) {
      if (data.isVideoAnalysis && data.isVideoAnalysis === 1) {
        // 烟火视频分析弹窗
        openPopup("DeviceDetails", markId);
      } else {
        showVideoClient(data.id, data.videoList, markId);
      }
    } else {
      message("无关联视频！", "warning");
      return;
    }
  });
}
/* 播放视频 */
function showVideoClient(videoIds, videoList, markId) {
  if (!videoIds && (!videoList || videoList.length < 1)) {
    message("无关联视频！", "warning");
    return;
  }
  if (videoList) {
    showVideos(videoList, markId);
  } else {
    getVideoByIds({
      videoIds: videoIds
    }).then(res => {
      showVideos(res.data, markId);
    });
  }
}

function showVideos(videoList, markId) {
  if (videoList && videoList.length > 0) {
    //找到关联的视频列表里没离线的
    let hasFlag = false;
    $.each(videoList, (index, data) => {
      if (data.isOnline) {
        topVue.$Cs.openRelatedPages(
          10108,
          String(markId ? markId : ""),
          JSON.stringify({
            authId: data.authId ? data.authId : '',
            orgid: data.organizationId ? data.organizationId : "",
            cameraId: data.deviceId ? data.deviceId : "",
            name: data.name ? data.name : "",
            channel: data.channel ? data.channel : "",
            type: data.type ? data.type : 0,
            isOnLine: 1
          })
        );
        if (isCs()) {} else {
          message("请在客户端内打开视频！", "warning");
        }
        hasFlag = true;
      }
    });
    if (!hasFlag) {
      message("该视频已离线！", "warning");
    }
  } else {
    message("无关联视频！", "warning");
  }
}
/*---- 语音轮播跑马灯 start -----*/
/* @语音指令 */
function voiceCmd(isClose = 0) {
  if (!getClickEnabel(1)) return;
  if (isCs(true)) {
    topVue.$Cs.openRelatedPages(10107, "", isClose.toString());
  } else {
    window.FunList.openAudioDiscern(isClose);
  }
}
/* @打开推送语音模块 */
function openPushAudioCtl(audioUrl, tips, muted) {
  if (audioUrl.indexOf('http') != 0) {
    audioUrl = location.origin + audioUrl
  }
  if (isCs(true)) {
    topVue.$Cs.openRelatedPages(10107, audioUrl, tips);
  } else {
    window.FunList.openPushAudio(audioUrl, tips, muted);
  }
}
/* @设置识别结果（识别回调） */
function setDiscernResultCtl(data) {
  window.FunList.setDiscernResult && window.FunList.setDiscernResult(data);
}
/* @关闭识别功能 */
function closeDiscern() {
  window.FunList.closeDiscern && window.FunList.closeDiscern();
}
/*---- 语音轮播跑马灯 end -----*/
/*---- 语义识别  start-----*/
/* @设置弹框里识别结果 */
function setAudioDisposeCtl(data) {
  if (isCs(true)) {
    topVue.$Cs.openRelatedPages(10110, "1", JSON.stringify(data));
  } else {
    window.FunList.setAudioDispose && window.FunList.setAudioDispose(data);
  }
}
/* @执行识别结果命令词识别结果 */
function excuteCmdResult(data) {
  if (isCs(true)) {
    topVue.$Cs.openRelatedPages(10110, "", JSON.stringify(data));
  } else {
    window.FunList.excuteCmdResult && window.FunList.excuteCmdResult(data);
  }
}
/* @关闭识别结果处理 */
function closeAudioDisposeCtl() {
  if (isCs(true)) {
    topVue.$Cs.closeDetailsPage(10110);
  } else {
    window.FunList.closeAudioDispose && window.FunList.closeAudioDispose();
  }
}
/* @语义识别执行跳转命令 */
function excuteAudioCmdCtl(rslt) {
  rslt = JSON.parse(rslt);
  topVue.$store.commit('setSpeechData', rslt)
  let isMuilUnitUser = topVue.$store.state.userInfo.isMuilUnitUser; //0:单单位用户;1:多单位用户
  let CmdOrgIds = topVue.$store.state.userInfo.organizationIds;
  let firstOrgId = CmdOrgIds.split(",")[0];
  let parames = {
    orgId: CmdOrgIds
  };
  // 若有传参，先合并参数
  if (rslt.parames) {
    Object.assign(parames, rslt.parames);
  }

  switch (rslt.action) {
    case 100000:
      //关闭监控中心大屏
      closeSystem();
      break;
    case 100001:
      //刷新系统
      location.reload();
      break;
    case 100100:
      //关闭语义识别助手
      voiceCmd(1);
      closeAudioDisposeCtl();
      break;
    case 100200:
      //打开工具箱
      openPopup("ToolsMap");
      break;
    case 100201:
      //关闭工具箱
      closePopup("ToolsMap");
      break;
    case 100202:
      //开始飞行
      if (isCs(true)) {
        topVue.$Cs.tooltype3d(14);
      }
      break;
    case 100203:
      //停止飞行
      if (isCs(true)) {
        topVue.$Cs.tooltype3d(15);
      }
      break;
    case 100204:
      //暂停飞行
      if (isCs(true)) {
        topVue.$Cs.tooltype3d(14);
      }
      break;
    case 100205:
      //加速飞行
      if (isCs(true)) {
        topVue.$Cs.tooltype3d(16);
      }
      break;
    case 100206:
      //减速飞行
      if (isCs(true)) {
        topVue.$Cs.tooltype3d(13);
      }
      break;
    case 100207:
      //切换地图主题
      changeThemeMap();
      break;
    case 100300:
      //打开系统设置
      openPopup("WebsocketSet");
      break;
    case 100301:
      //关闭系统设置
      closePopup("WebsocketSet");
      break;
    case 100400:
      //返回平台首页
      backHome();
      break;
    case 100500:
      //打开单位首页
      topVue.$store.commit('setCurrentOrgId', rslt.orgId || firstOrgId)
      enterSingleHome({
        orgId: rslt.orgId || firstOrgId,
        isRefresh: true,
      });
      break;
    case 100501:
      //关闭单位首页
      backHome();
      break;
    case 100600:
      //打开设备一张图
      enterChild("MapEquipment", {
        markType: 0,
        orgIds: CmdOrgIds
      });
      break;
    case 100601:
      //关闭设备一张图
      backProvePage();
      break;
    case 100602:
      //打开设备一张图
      enterChild("MapEquipment", {
        markType: rslt.parames.markType || 0,
        orgIds: CmdOrgIds
      });
      break;
    case 100700:
      //查看高危信号详情
      // 判断当前用户是否为多单位用户
      if (isMuilUnitUser == 1) {
        enterDetail("HighRiskSignal", parames);
      } else {
        message("当前用户无权限查看！", "warning");
      }
      break;
    case 100701:
      //关闭高危信号详情
      backProvePage();
      break;
    case 100800:
      //查看重大问题详情
      // 判断当前用户是否为多单位用户
      if (isMuilUnitUser == 1) {
        enterDetail("ImportQuestion", parames);
      } else {
        message("当前用户无权限查看！", "warning");
      }
      break;
    case 100801:
      //关闭重大问题详情
      backProvePage();
      break;
    case 100900:
      //打开安全指数详情
      enterDetail("FireSafetyAssess", {
        orgId: rslt.orgId || firstOrgId
      });
      break;
    case 100901:
      //关闭安全指数详情
      backProvePage();
      break;
    case 100902:
      //打开安全指数
      fixedPosition(rslt.parames.mapLocation)
      break;
    case 101000:
      //打开呼叫中心详情
      enterChild("CellCenter", {
        orgId: CmdOrgIds
      });
      break;
    case 101001:
      //关闭呼叫中心详情
      backProvePage();
      break;
    case 101002:
      //切换到视频通话
      changeCellType(2);
      break;
    case 101003:
      //切换到语意通话
      changeCellType(1);
      break;
    case 101004:
      //打开呼叫中心详情&呼叫xxx
      enterChild("CellCenter", {
        orgId: CmdOrgIds,
        isRefresh: true
      });
      break;
    case 101100:
      //打开接处警详情
      enterChild("ReceivingPolice", {
        orgIds: CmdOrgIds,
        isRefresh: true
      });
      break;
    case 101101:
      //关闭接处警详情
      backProvePage();
      break;
    case 101200:
      //打开日常巡检详情
      enterChild("Inspection", {
        orgIds: CmdOrgIds,
        isRefresh: true
      });
      break;
    case 101201:
      //关闭日常巡检详情
      backHome();
      break;
    case 101300:
      //打开隐患整改详情
      enterChild("RectificationDangers", {
        orgIds: CmdOrgIds,
        isRefresh: true
      });
      break;
    case 101301:
      //关闭隐患整改详情
      backProvePage();
      break;
    case 101302:
      //打开隐患整改清单视图
      enterDetail("HiddenDangers", {
        orgId: CmdOrgIds
      });
      break;
    case 101400:
      //打开消防维保详情
      enterChild("Maintenance", {
        orgIds: CmdOrgIds,
        isRefresh: true
      });
      break;
    case 101401:
      //关闭消防维保详情
      backProvePage();
      break;
    case 101402:
      //打开消防维保时间视图
      enterDetail("MaintenanceTimeLine", {
        orgId: CmdOrgIds
      });
      break;
    case 101403:
      //关闭消防维保时间视图
      backProvePage();
      break;
    case 101500:
      //打开设备详情
      enterDetail("EquipmentList", parames);
      break;
    case 101501:
      //关闭设备详情
      backProvePage();
      break;
    case 101600:
      //TODO:打开到室内场景？
      break;
    case 101601:
      //TODO:返回到室外场景
      break;
    case 101700:
      // 展开接入单位
      window.FunList.openUnitList(1);
      break;
    case 101800:
      // 展开报警单位
      window.FunList.openUnitList(2);
      break;
    case 101701:
      // 收缩接入单位
      window.FunList.closeUnitList();
      break;
    case 101801:
      // 收缩报警单位
      window.FunList.closeUnitList();
      break;
    case 101900:
      // 展开/收缩安全指数排名
      window.FunList.openSafeScoreList();
      break;
    default:
      break;
  }
}
/*---- 语义识别  end-----*/

/* @探测器地图定位 
* @param { Int fcfId } 探测器id
  @param { Boolean fullscreenMap }是否跳转到设备一张图
*/
function fixedPosition_fc(fcfId, isFullscreenMap = false) {
  let type = localStorage.getItem("ilinkBs_currentMapType")
  //获取设备的坐标信息
  getBsMarkInfo({
    fcfId: fcfId, //消防设施编码
    dType: type == 4 ? 2 : type // unity地图不提供定位
  }).then(res => {
    if (!res.data) {
      message("暂无位置信息！", "warning");
      return;
    }
    if (isFullscreenMap) {
      enterChild("MapEquipment", {
        markType: res.data.type,
        orgIds: res.data.orgId,
        name: res.data.name,
        fcfId: res.data.bizId
      });
    }
    fixedPosition(res.data);
  });
}
/* @地图定位
 * @param { isAround } 是否设备周边定位
 */
function fixedPosition(row, isAround) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (topVue.bsConfig.MapOptions.svgMap) {
    if (row)
      window.ZHXF_FOCUS_UNIT_MAP(row.orgId)
    return
  }
  if (!row || (!row.info3d && !row.mapLocation && !row.lon)) {
    message("暂无位置信息！", "warning");
    return;
  }
  if (mapType == 4 && row.type == 1) {
    return window.FunList.unityFlightToMark && window.FunList.unityFlightToMark(row.name)
  }
  if (row.orgId) {
    topVue.$store.commit('setCurrentOrgId', row.orgId)
  }
  if (mapType == 4) {
    topVue.$store.commit('setIsOutDoor', 0)
    topVue.$store.commit('setCurrentMapType', 2)
    mapType = 2
  }
  if (topVue.bsConfig.MapOptions.svgMap) {

  } else if (mapType == 1) {
    let location = row.info3d ?
      JSON.parse(row.info3d) :
      row.mapLocation ?
      JSON.parse(row.mapLocation) :
      row.lon ? {
        lon: row.lon,
        lat: row.lat
      } :
      "";
    if (location) {
      let obj = {
        lon: location.lon,
        lat: location.lat,
        id: row.id,
        type: row.type,
        name: row.name
      };
      window.FunList.fixedPosition_BaiduMap && window.FunList.fixedPosition_BaiduMap(obj);
    } else {
      message("暂无位置信息！", "warning");
      return;
    }
  } else if (mapType == 2) {
    if (isAround) {
      window.FunList.peripheryLocation_FMap(row);
    } else {
      let location = row.info3d ?
        JSON.parse(row.info3d)[0] :
        row.mapLocation ?
        JSON.parse(row.mapLocation)[0] :
        "";
      if (location) {
        let obj = {
          x: location.x,
          y: location.y,
          groupId: location.indoorId,
          id: row.id,
          indoorMapId: row.indoorMapId,
          bizId: row.bizId,
          type: row.type,
          name: row.name,
          hiddenDetail: row.hiddenDetail,
          location: row.info3d || row.mapLocation
        };
        window.FunList.fixedPosition_FMap(obj);
      } else {
        return;
      }
    }
  } else if (mapType == 3) {
    let location = row.info3d ?
      row.info3d :
      row.mapLocation ?
      row.mapLocation :
      "";
    if (location) {
      topVue.$Cs.openFlight(location);
    } else {
      message("暂无位置信息！", "warning");
      return;
    }
  }
}

/* 刷新echart */
function resizeCharts() {
  $.each(topVue.$root.charts, (index, chartObj) => {
    chartObj.resize && chartObj.resize();
  });
}

/* 蜂鸟地图重新获取标注数据，eg：设备一张图、隐患、巡检、维保
    markType 0/32/22/33 
*/
function refreshMapMarkerDataToFmap(callback) {
  let currentPage = getCurrentPage().name;
  if (currentPage == "Home" || currentPage == "SingleHome") {
    //设备一张图
    let gisInfo = JSON.parse(localStorage.getItem("ilinkBs_mapGisInfo"));
    init3dData({
      orgIds: topVue.$store.state.currentOrgId || topVue.$store.state.userInfo.organizationIds,
      dtype: 2,
      types: topVue.bsConfig.HomeMarkTypes,
      indoorMapId: gisInfo.id || "",
      indoorId: gisInfo.indoorId || ""
    }).then(re => {
      if (re.data) {
        let dataStr = Base64.decode(re.data);
        localStorage.setItem("ilinkBs_mapData", dataStr);
        setMapMark(JSON.parse(dataStr) || "", true, true);
        callback && callback()
      }
    });
  } else if (currentPage == "MapEquipment") {
    //设备一张图
    window.FunList.refreshmapEquip && window.FunList.refreshmapEquip(() => {
      callback && callback()
    });
  } else if (
    currentPage == "RectificationDangers" ||
    currentPage == "ReceivingPolice"
  ) {
    //隐患
    let gisInfo = JSON.parse(localStorage.getItem("ilinkBs_mapGisInfo"));
    init3dData({
      orgIds: topVue.$store.state.currentOrgId || topVue.$store.state.userInfo.organizationIds,
      dtype: 2,
      types: topVue.bsConfig.HomeMarkTypes,
      indoorMapId: gisInfo.id || "",
      indoorId: gisInfo.indoorId || ""
    }).then(re => {
      if (re.data) {
        let mapData = JSON.parse(Base64.decode(re.data));
        localStorage.setItem("ilinkBs_mapData", Base64.decode(re.data));
        if (currentPage == "RectificationDangers") {
          let hiddenArr = [];
          if (mapData && mapData.hidden && mapData.hidden[0]) {
            hiddenArr = mapData.hidden[0].data;
          }
          setMapMark({
              32: hiddenArr
            },
            true,
            false
          );
        } else if (currentPage == "ReceivingPolice") {
          let modelStatusArr = {};
          $.each(mapData.modelStatus, (index, obj) => {
            modelStatusArr[obj.type] = obj.data;
          });
          setMapMark(modelStatusArr, true, false);
        }
        callback && callback()
      }
    });
  } else if (currentPage == "Inspection") {
    //巡检
    window.FunList.refreshmapInspect && window.FunList.refreshmapInspect();
    callback && callback()
  } else if (currentPage == "Maintenance") {
    //维保
    window.FunList.refreshmapMaintenance && window.FunList.refreshmapMaintenance();
    callback && callback()
  } else {
    window.FunList.drawMapMark([]);
    callback && callback()
  }
}

/* @初始化地图 */
/*  * @param { Int orgId }
    * @param { Int mapType }1 百度 2室内地图 3三维
      @param { Fn cb }
    * @param { Int idType }	type为2时才传值 0:组织平台 1:业主单位 2:建筑物 3:九小场所
    * @param { Object gisInfo}	避免重复调用接口
 */
async function setMapOptions(orgId, mapType, cb, idType = 1, gisInfo) {
  topVue.$store.commit('setCurrentMapType', mapType)
  let param = {
    bizId: orgId,
    type: mapType
  };
  if (mapType == 2) {
    param.idType = idType;
    param.type = 2
    if (cb != null) {
      orgId = topVue.$store.state.userInfo.organizationIds;
    }
  }
  if (!gisInfo && !topVue.bsConfig.MapOptions.svgMap) {
    const res = await initGisInfo(param);
    if (res.data) {
      gisInfo = res.data.gisInfo || {};
    }
  }
  localStorage.setItem("ilinkBs_mapGisInfo", JSON.stringify(gisInfo || {}));
  if (mapType == 3) {
    let objMark = {
      id: gisInfo.platId,
      name: "",
      icon: "",
      workName: gisInfo.workName,
      sceneName: gisInfo.sceneName,
      info3d: gisInfo.info3d, //3d信息，json字符串
      remark: gisInfo.remark
    };
    topVue.$Cs.start3D(JSON.stringify(objMark));
  } else {
    window.FunList.drawMapBydata && window.FunList.drawMapBydata(mapType, gisInfo, cb);
  }
}

/* @初始化地图标注信息 */
/*  * @param { String orgIds }
      @param { Int mapType }1 百度 2室内地图 3三维
      @param { Object gisInfo }地图初始化信息
    *
 */
function intMapMarks(
  orgIds = topVue.$store.state.userInfo.organizationIds,
  markTyps = topVue.bsConfig.HomeMarkTypes,
  gisInfo
) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  let param = {
    orgIds: orgIds,
    dtype: mapType,
    types: markTyps
  };
  if (mapType == 2) {
    param.indoorMapId = gisInfo.id || "";
    param.indoorId = gisInfo.indoorId || "";
  }
  init3dData(param).then(re => {
    if (mapType == 3) {
      topVue.$Cs.info3dMark(re.data || ""); //把server端base64数据给c端
      if (localStorage.getItem('Build_Top') != 2) { // 报警数
        topVue.$Cs.markersShowCtrl("92", 1);
        topVue.$Cs.markersShowCtrl("51", 2);
      } else { // 设备正常率
        topVue.$Cs.markersShowCtrl("51", 1);
        topVue.$Cs.markersShowCtrl("92", 2);
      }
    } else {
      if (re.data) {
        let dataStr = Base64.decode(re.data);
        localStorage.setItem("ilinkBs_mapData", dataStr);
        let dataObj = JSON.parse(dataStr) || "";
        if (orgIds.toString().split(",").length < 2 && !topVue.$store.state.userInfo.isMuilUnitUser) {
          //单单位首页
          dataObj && delete dataObj.score; //多单位首页才展示分数
        } else {
          //多单位首页
          $.each(dataObj.top, (index, obj) => {
            if (obj.type == 51) {
              //单单位首页才展示楼栋警情概况
              dataObj.top[index].data = [];
            }
          });
        }
        setMapMark(dataObj, true, true);
      }
    }
  });
}

/* @切换地图标注物 */
/*  *  @param { Obejct markArr } 标注物对象集合,eg:{type:arr}
/*  *  @param { Boolean isClear } 是否清空地图标注物，默认true
/*  *  @param { Boolean isFormHome } 是否首页，默认false
    *
 */
function setMapMark(markArr, isClear = true, isFormHome = false) {
  if (isCs(true)) {
    let markType = 0;
    if (markArr[22]) {
      // 巡检
      markType = 22;
    } else if (markArr[33]) {
      // 维保
      markType = 33;
    }
    if (markType && markArr[markType]) {
      topVue.$Cs.liveUpdate(
        JSON.stringify([{
          data: markArr[markType] || [],
          type: markType
        }])
      );
    }
  } else {
    window.FunList.drawMapMark(markArr || [], isClear, isFormHome);
  }
}

/* 初始化推送 */
function init_webSocket() {
  // if (location.origin.indexOf('localhost') > -1) return
  //初始化websocket
  const that = this;
  // 创建websocket连接
  window.wsForBs = new ReconnectingWebSocket(location.origin.replace('https', 'wss').replace('http', 'ws') + '/websocket');
  window.wsForBs.onopen = function () {
    console.log("socket开启...");
    // websocketBind(event);
  };
  window.wsForBs.onclose = function (event) {
    console.log("socket关闭...");
  };
  window.wsForBs.onmessage = function (event) {
    websocketBind(event);
  };
  window.wsForBs.onerror = function () {
    console.log("socket出现错误...");
  };
  // 创建websocket绑定分流
  let websocketBind = function (event) {
    // 模拟警情
    // let data = {"data":{"organizationId":"179","markInfo":{"fmapInfo":{"indoorMapId":8,"typeGroup":1,"buildId":1801,"createAccount":"kdAdmin","type":20,"orgId":179,"indoorId":"7","createTime":1602731140000,"bizId":"75368","name":"3—17光电探头","x":"13479319.914355712","y":"3674149.6312579853","z":"0","id":7730,"fireTType":0,"height":"2.5","mapLocation":"[{\"x\":13479319.914355712,\"y\":3674149.6312579853,\"z\":0,\"height\":2.5,\"indoorId\":7}]"}},"voiceUrl":"resource/2020/10/17/5h77WQisOMUERBeCM5qfUm00-77c99291ad9d4936bd3ef4debd0a278a.wav","handlerStatus":"-1","fbsMarkInfo":{"info3D":{"platId":178,"createTime":1573034569000,"info3d":"{'lon':117.25195351299514,'lat':31.841361746969682,'alt':72.05584135837853,'rotateX':0.0,'rotateY':0.0,'rotateZ':180.0,'zoomX':4.6815075874328613,'zoomY':4.6815075874328613,'zoomZ':4.6815075874328613,'objProp':null,'viewLon':117.2521896362468,'viewLat':31.83993632087833,'viewAlt':103.96295204758644,'viewTilt':71.8215964796152,'viewHeading':343.79386928550542}","bizId":1754,"name":"图书馆","location":"科大西区图书馆","remark":"","updateTime":1573799227000,"id":451,"type":2,"orgId":179},"fmapInfo":{"indoorMapId":7,"typeGroup":10,"createAccount":"xqAdmin","type":2,"orgId":179,"indoorId":"1","createTime":1602733943000,"bizId":"1754","name":"图书馆","x":"13481406.503163043","y":"3671862.0738926055","z":"0","id":7755,"fireTType":0,"height":"2.5","mapLocation":"[{\"x\":13481406.503163043,\"y\":3671862.0738926055,\"z\":0,\"height\":2.5,\"indoorId\":1}]"}},"fcfsId":"75368","businessId":"41296355","voiceDesc":"【报警】请注意：图书馆>6楼>图书馆3—17光电探头报警，请立即处理","count":"9","fbsId":"1801","fireTType":"10","status":"10"},"total":1,"type":41020}
    if (event.data) {
      let data = JSON.parse(event.data);
      that.getPushData(data);
      topVue.$store.commit('setWsData', data)
    }
  };
}

function getPushData(data) {
  if (data != null) {
    let type = data.type;
    let wsData = data.data;
    let isMuilUnitUser = topVue.$store.state.userInfo.isMuilUnitUser;
    let wsfilterArr = getPushConfig() || [];
    let [pushHigh, pushHighAudio] = [true, true];
    let [pushImportant, pushImportantAudio] = [true, true];
    let [pushAlarm, pushAlarmAudio] = [true, true];
    let [pushHidden, pushHiddenAudio] = [true, true];
    let [pushPropelling, pushPropellingAudio] = [true, true];
    $.each(wsfilterArr, (index, filterObj) => {
      if (filterObj.type == 401) {
        pushHigh = filterObj.switch == 1 ? true : false;
        pushHighAudio = filterObj.Mute == 0 ? true : false;
      } else if (filterObj.type == 402) {
        pushImportant = filterObj.switch == 1 ? true : false;
        pushImportantAudio = filterObj.Mute == 0 ? true : false;
      } else if (filterObj.type == 403) {
        pushAlarm = filterObj.switch == 1 ? true : false;
        pushAlarmAudio = filterObj.Mute == 0 ? true : false;
      } else if (filterObj.type == 404) {
        pushHidden = filterObj.switch == 1 ? true : false;
        pushHiddenAudio = filterObj.Mute == 0 ? true : false;
      } else if (filterObj.type == 405) {
        pushPropelling = filterObj.switch == 1 ? true : false;
        pushPropellingAudio = filterObj.Mute == 0 ? true : false;
      }
    });
    var Obj = {
      接收到推送消息: {
        type: type,
        wsData: wsData
      }
    };
    console.table(Obj);
    //推送类型 40*卡片推送、 41*GIS推送 、 42*单位测试推送*
    switch (type) {
      case 40010: //报警单位发生推送
        if (wsData && isMuilUnitUser) {
          //修改报警单位数量
          if (isCs(true)) {
            topVue.$Cs.openRelatedPages(
              10401,
              "40010",
              JSON.stringify(wsData)
            );
          } else {
            window.FunList.alertUnitNum_ws &&
              window.FunList.alertUnitNum_ws(wsData);
          }
        }
        break;
      case 40020: //核心指标推送（高危信号发生|复位|处理）
        if (wsData && isMuilUnitUser && pushHigh) {
          //播放音频
          openPushAudioCtl(wsData.voiceUrl, wsData.voiceDesc, !pushHighAudio);
          //修改高危信号数量
          if (isCs(true)) {
            topVue.$Cs.openRelatedPages(
              10401,
              "40020",
              JSON.stringify(wsData)
            );
          } else {
            window.FunList.highRiskFireCount_ws &&
              window.FunList.highRiskFireCount_ws(wsData);
          }
        }
        break;
      case 40021: //核心指标推送（重大问题发生|复位|处理）
        if (wsData && isMuilUnitUser && pushImportant) {
          //播放音频
          openPushAudioCtl(wsData.voiceUrl, wsData.voiceDesc, !pushImportantAudio);
          //修改重大问题数量
          if (isCs(true)) {
            topVue.$Cs.openRelatedPages(
              10401,
              "40021",
              JSON.stringify(wsData)
            );
          } else {
            window.FunList.importantCount_ws &&
              window.FunList.importantCount_ws(wsData);
          }
        }
        break;
      case 40030: //安全指数排名推送
        if (wsData && isMuilUnitUser) {
          // 修改多单位安全指数排名
          if (isCs(true)) {
            topVue.$Cs.openRelatedPages(
              10401,
              "40030",
              JSON.stringify(wsData)
            );
          } else {
            window.FunList.orgsSafetyScore_ws &&
              window.FunList.orgsSafetyScore_ws(wsData);
          }
        }
        break;
      case 40031: //安全指数推送
        if (wsData) {
          if (isMuilUnitUser) {
            // 地图修改
            pushMapMark(wsData, 34);
          } else {
            // 修改单单位安全指数
            if (isCs(true)) {
              topVue.$Cs.openRelatedPages(10401, "40031", "");
            } else {
              window.FunList.sigeleOrgSafetyScore_ws && wsData.deductDetail &&
                window.FunList.sigeleOrgSafetyScore_ws(wsData.deductDetail);
            }
          }
        }
        break;
      case 40040: //呼叫中心推送
        // 刷新接口
        if (isCs(true)) {
          topVue.$Cs.openRelatedPages(10402, "40040", "");
        } else {
          window.FunList.cardCellCenter_ws &&
            window.FunList.cardCellCenter_ws(wsData);
        }
        break;
      case 40050: //接处警推送
        if (wsData) {
          //多、单联网单位首页卡片接处警更新
          if (isCs(true)) {
            topVue.$Cs.openRelatedPages(
              10402,
              "40050",
              JSON.stringify(wsData)
            );
          } else {
            window.FunList.pickUpPolice_ws &&
              window.FunList.pickUpPolice_ws(wsData);
          }
        }
        break;
      case 40060: //日常巡检推送
        if (wsData && isMuilUnitUser) {
          //多联网单位首页卡片日常巡检修改
          if (isCs(true)) {
            topVue.$Cs.openRelatedPages(
              10402,
              "40060",
              JSON.stringify(wsData)
            );
          } else {
            window.FunList.orgsDailyInspect_ws &&
              window.FunList.orgsDailyInspect_ws(wsData);
          }
        }
        break;
      case 40061: //日常巡检推送
        if (wsData) {
          //单联网单位首页卡片日常巡检修改
          if (isCs(true)) {
            topVue.$Cs.openRelatedPages(
              10402,
              "40061",
              JSON.stringify(wsData)
            );
          } else {
            window.FunList.sigeleOrgDailyInspect_ws &&
              window.FunList.sigeleOrgDailyInspect_ws(wsData);
          }
        }
        break;
      case 40070: //隐患整改推送
        //多、单联网单位首页卡片隐患整改修改,刷新接口
        if (pushHidden) {
          if (isCs(true)) {
            topVue.$Cs.openRelatedPages(10402, "40070", "");
          } else {
            window.FunList.hiddenDangerRectification_ws &&
              window.FunList.hiddenDangerRectification_ws();
          }
        }
        break;
      case 40080: //消防供水推送
        //刷新接口
        if (isCs(true)) {
          topVue.$Cs.openRelatedPages(10402, "40080", "");
        } else {
          window.FunList.fireWaterSupply_ws &&
            window.FunList.fireWaterSupply_ws(wsData);
        }
        break;
      case 40090: //电气火灾推送
        //刷新接口
        if (isCs(true)) {
          topVue.$Cs.openRelatedPages(10402, "40090", "");
        } else {
          window.FunList.electricalFire_ws &&
            window.FunList.electricalFire_ws(wsData);
        }
        break;
      case 40100: //消防维保推送
        //刷新接口
        if (isCs(true)) {
          topVue.$Cs.openRelatedPages(10402, "40100", "");
        } else {
          window.FunList.fireMaintenance_ws &&
            window.FunList.fireMaintenance_ws(wsData);
        }
        break;
      case 41010: //隐患推送
        if (wsData && pushHidden) {
          //播报音频
          openPushAudioCtl(wsData.voiceUrl, wsData.voiceDesc, !pushHiddenAudio);
          //地图修改
          //多、单联网单位首页首页隐患GIS修改
          if (pushPropelling) {
            pushMapMark(wsData, 32);
          }
        }
        break;
      case 41020: //警情发生的推送
        if (wsData && pushAlarm) {
          //播报音频
          openPushAudioCtl(wsData.voiceUrl, wsData.voiceDesc, !pushAlarmAudio);
          // voiceCmd(0)
          // 视频AI卡片推送
          window.FunList.cardAICloudVideo_ws &&
            window.FunList.cardAICloudVideo_ws(wsData);
          //地图修改
          //修改多、单联网单位首页警情GIS
          if (pushPropelling) {
            pushMapMark(wsData, 51);
            pushMapMark(wsData, 0);
          }
        }
        break;
      case 41021: //警情处理（领取，处理）的推送
        if (wsData && pushAlarm) {
          //播报音频
          openPushAudioCtl(wsData.voiceUrl, wsData.voiceDesc, !pushAlarmAudio);
          //地图修改
          //多、单联网单位首页警情GIS修改 搁置
        }
        break;
      case 41022: //警情复位的推送
        if (wsData && pushAlarm) {
          //播报音频
          openPushAudioCtl(wsData.voiceUrl, wsData.voiceDesc, !pushAlarmAudio);
          //地图修改
          //多、单联网单位首页警情GIS修改
          if (pushPropelling) {
            pushMapMark(wsData, 51);
            pushMapMark(wsData, 0);
          }
        }
        break;
      case 41023: //syg：三分钟未处理警情  增加推送类型41023   数据结果跟处理警情是一样的  只是类型不一样
        if (wsData && pushAlarm) {
          //播报音频
          openPushAudioCtl(wsData.voiceUrl, wsData.voiceDesc, !pushAlarmAudio);
          //地图修改
          //多、单联网单位首页警情GIS修改
          if (pushPropelling) {
            pushMapMark(wsData, 51);
            pushMapMark(wsData, 0);
          }
        }
        break;
      case 42000: //测试单位推送
        if (wsData) {
          //播报音频
          openPushAudioCtl(wsData.voiceUrl, wsData.voiceDesc);
          //TODO:修改测试信息 -- 暂不做
        }
        break;
      default:
        break;
    }
  }
}

/* @首页推送定位 */
/*  *  @param { Obejct markArr } 标注物对象集合,eg:{type:arr}
     说明：警情和隐患定位，其他的只更新数据
    *
 */
function pushMapMark(wsData, pushMarkType) {
  if (topVue.bsConfig.MapOptions.svgMap) {
    window.ZHXF_ALARM_NUM()
    return
  }
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  // unity地图跳转至蜂鸟地图定位
  if (mapType == 4) mapType = 2
  let currentPage = getCurrentPage().name;
  //除了三维外，其他地图种类只在首页推送
  if (mapType !== 3 && currentPage != "Home" && currentPage != "SingleHome") return;
  // 非当前单位的不定位
  let orgId = wsData.organizationId || wsData.orgId
  if (currentPage == 'SingleHome' && topVue.$store.state.currentOrgId != orgId) return
  let markType = pushMarkType;
  let indoorMapId = "";
  let indoorId = "";
  let markObj = {};
  if (pushMarkType == 34) {
    // 安全指数推送
    markObj = {
      name: wsData.orgName,
      val: wsData.safetyScore,
      orgId: wsData.orgId
    };
    if (mapType == 1) {
      if (!wsData.markInfo.info2D || !wsData.markInfo.info2D.lon) return;
      markObj.id = wsData.markInfo.info2D.id;
      markObj.info3d = JSON.stringify({
        lon: parseFloat(wsData.markInfo.info2D.lon),
        lat: parseFloat(wsData.markInfo.info2D.lat)
      });
    } else if (mapType == 2) {
      if (
        !wsData.markInfo.fmapInfo ||
        !wsData.markInfo.fmapInfo.mapLocation
      )
        return;
      markObj.id = wsData.markInfo.fmapInfo.id;
      markObj.info3d = wsData.markInfo.fmapInfo.mapLocation;
      indoorMapId = wsData.markInfo.fmapInfo.indoorMapId;
      indoorId = wsData.markInfo.fmapInfo.indoorId;
    } else {
      if (!wsData.markInfo.info3D || !wsData.markInfo.info3D.info3d)
        return;
      markObj.id = wsData.markInfo.info3D.id;
      markObj.status = "";
      markObj.info3d = wsData.markInfo.info3D.info3d;
    }
  } else if (pushMarkType == 32) {
    // 隐患推送
    if (!wsData.fbsMarkInfo && !wsData.markInfo) return;
    markObj = {
      hiddenDetail: {
        id: wsData.businessId,
        desc: wsData.voiceDesc,
        picUrls: wsData.pic_urls,
        status: wsData.status
      },
      id: "",
      name: wsData.name || ""
    };
    if (mapType == 1) {
      if (
        wsData.fbsMarkInfo &&
        wsData.fbsMarkInfo.info2D &&
        wsData.fbsMarkInfo.info2D.lon
      ) {
        markObj.id = wsData.fbsMarkInfo.info2D.id;
        markObj.info3d = JSON.stringify({
          lon: parseFloat(wsData.fbsMarkInfo.info2D.lon),
          lat: parseFloat(wsData.fbsMarkInfo.info2D.lat)
        });
      } else if (
        wsData.markInfo &&
        wsData.markInfo.info2D &&
        wsData.markInfo.info2D.lon
      ) {
        markObj.id = wsData.markInfo.info2D.id;
        markObj.info3d = JSON.stringify({
          lon: parseFloat(wsData.markInfo.info2D.lon),
          lat: parseFloat(wsData.markInfo.info2D.lat)
        });
      } else {
        return;
      }
    } else if (mapType == 2) {
      if (
        wsData.fbsMarkInfo &&
        wsData.fbsMarkInfo.fmapInfo &&
        wsData.fbsMarkInfo.fmapInfo.mapLocation
      ) {
        markObj.id = wsData.fbsMarkInfo.fmapInfo.id;
        markObj.info3d = wsData.fbsMarkInfo.fmapInfo.mapLocation;
        indoorMapId = wsData.fbsMarkInfo.fmapInfo.indoorMapId;
        indoorId = wsData.fbsMarkInfo.fmapInfo.indoorId;
      } else if (
        wsData.markInfo &&
        wsData.markInfo.fmapInfo &&
        wsData.markInfo.fmapInfo.mapLocation
      ) {
        markObj.id = wsData.markInfo.fmapInfo.id;
        markObj.info3d = wsData.markInfo.fmapInfo.mapLocation;
        indoorMapId = wsData.markInfo.fmapInfo.indoorMapId;
        indoorId = wsData.markInfo.fmapInfo.indoorId;
      } else {
        return;
      }
    } else {
      markObj.status = wsData.status;
      markObj.val = markObj.hiddenDetail;
      if (
        wsData.fbsMarkInfo &&
        wsData.fbsMarkInfo.info3D &&
        wsData.fbsMarkInfo.info3D.info3d
      ) {
        markObj.id = wsData.fbsMarkInfo.info3D.id;
        markObj.info3d = wsData.fbsMarkInfo.info3D.info3d;
      } else if (
        wsData.markInfo &&
        wsData.markInfo.info3D &&
        wsData.markInfo.info3D.info3d
      ) {
        markObj.id = wsData.markInfo.info3D.id;
        markObj.info3d = wsData.markInfo.info3D.info3d;
      } else {
        return;
      }
    }
  } else if (pushMarkType == 51) {
    // 楼栋警情概况
    if (!wsData.fbsMarkInfo) return;
    markObj = {
      val: {
        count: wsData.count || 0,
        orgId: wsData.organizationId,
        status: wsData.status || 0
      }
    };
    if (mapType == 1) {
      if (!wsData.fbsMarkInfo.info2D || !wsData.fbsMarkInfo.info2D.lon)
        return;
      markObj.id = wsData.fbsMarkInfo.info2D.id;
      markObj.info3d = JSON.stringify({
        lon: parseFloat(wsData.fbsMarkInfo.info2D.lon),
        lat: parseFloat(wsData.fbsMarkInfo.info2D.lat)
      });
    } else if (mapType == 2) {
      if (
        !wsData.fbsMarkInfo.fmapInfo ||
        !wsData.fbsMarkInfo.fmapInfo.mapLocation
      )
        return;
      markObj.id = wsData.fbsMarkInfo.fmapInfo.id;
      markObj.info3d = wsData.fbsMarkInfo.fmapInfo.mapLocation;
      indoorMapId = wsData.fbsMarkInfo.fmapInfo.indoorMapId;
      indoorId = wsData.fbsMarkInfo.fmapInfo.indoorId;
    } else {
      if (!wsData.fbsMarkInfo.info3D || !wsData.fbsMarkInfo.info3D.info3d)
        return;
      markObj.id = wsData.fbsMarkInfo.info3D.id;
      markObj.val = wsData.count || 0;
      markObj.status = wsData.status || 0;
      markObj.info3d = wsData.fbsMarkInfo.info3D.info3d;
    }
  } else {
    // 警情推送
    if (!wsData.markInfo) return;
    markObj = {
      status: wsData.fireTType
    };
    if (mapType == 1) {
      if (!wsData.markInfo.info2D || !wsData.markInfo.info2D.lon) return;
      markType = wsData.markInfo.info2D.type;
      markObj.id = wsData.markInfo.info2D.id;
      markObj.bizId = wsData.markInfo.info2D.bizId;
      markObj.name = wsData.markInfo.info2D.name;
      markObj.info3d = JSON.stringify({
        lon: parseFloat(wsData.markInfo.info2D.lon),
        lat: parseFloat(wsData.markInfo.info2D.lat)
      });
    } else if (mapType == 2) {
      if (!wsData.markInfo.fmapInfo) return;
      markType = wsData.markInfo.fmapInfo.type;
      markObj.id = wsData.markInfo.fmapInfo.id;
      markObj.bizId = wsData.markInfo.fmapInfo.bizId;
      markObj.name = wsData.markInfo.fmapInfo.name;
      markObj.info3d = wsData.markInfo.fmapInfo.mapLocation;
      indoorMapId = wsData.markInfo.fmapInfo.indoorMapId;
      indoorId = wsData.markInfo.fmapInfo.indoorId;
    } else {
      if (!wsData.markInfo.info3D || !wsData.markInfo.info3D.info3d)
        return;
      markType = wsData.markInfo.info3D.type;
      markObj.id = wsData.markInfo.info3D.id;
      markObj.bizId = wsData.markInfo.info3D.bizId;
      markObj.name = wsData.markInfo.info3D.name;
      markObj.val = "";
      markObj.info3d = wsData.markInfo.info3D.info3d;
    }
  }
  markObj.orgId = orgId
  if (mapType == 1) {
    window.FunList.pushDataToMap_BaiduMap &&
      window.FunList.pushDataToMap_BaiduMap(markType, markObj);
  } else if (mapType == 2) {
    // unity地图安全评分
    window.FunList.setMarkScoreUnity && window.FunList.setMarkScoreUnity(markObj.name, markObj.val);
    window.FunList.pushDataToMap_FMap && window.FunList.pushDataToMap_FMap(
      markType,
      markObj,
      indoorMapId,
      indoorId
    );
  } else {
    topVue.$Cs.policePush(
      markObj.id,
      markObj.name,
      markType,
      JSON.stringify(markObj.val),
      markObj.status,
      markObj.info3d
    );
  }
}

/* @切换地图类型 */
/*  *  @param { Int toType }1.baiduMap 2.fmap 3.三维
    目前只考虑到了三维只有一种的情况
*/
function switchMapType(toType = 1) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  closeDiscern();
  //如果在客户端中，并且有三维
  if (mapType == 3 || toType == 3) {
    //切换到三维
    topVue.$Cs.switchBsMap(toType);
    if (isCs()) {
      localStorage.setItem("ilinkBs_currentMapType", toType);
    } else {
      message("请在客户端内打开！", "warning");
    }
  } else {
    //切换到百度或者fmap
    localStorage.setItem("ilinkBs_currentMapType", toType);
    backHome(toType, false);
  }
}

/* @调蜂鸟整间距 */
function adjustSpacing(num) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (mapType == 1) {} else if (mapType == 2) {
    window.FunList.adjustSpacing_FMap(num);
  }
}
/* @切换地图主题 */
function changeThemeMap() {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (mapType == 1) {
    window.FunList.changeTheme_BaiduMap();
  } else if (mapType == 2) {
    window.FunList.changeTheme_FMap();
  }
}
/* @2/3D切换 */
function changeMode23D() {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (mapType == 1) {} else if (mapType == 2) {
    window.FunList.changeMode_FMap();
  }
}

/* @路况 */
function tranficStatus() {
  window.FunList.tranficStatus_BaiduMap();
}
/* @街景 */
function openPanoramaWind() {
  window.FunList.openPanoramaWind_BaiduMap();
}
/* @量距 */
function distanceMeasure() {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (mapType == 1) {} else if (mapType == 2) {
    window.FunList.distanceMeasure_FMap();
  }
}
/* @量高 */
function highMeasure() {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (mapType == 1) {} else if (mapType == 2) {
    window.FunList.highMeasure_FMap();
  }
}
/* @清除地图标记 */
function clearMapMark() {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (isCs(true)) {
    topVue.$Cs.tooltype3d(4);
  } else {
    if (mapType == 1) {
      window.FunList.clearanceMarkers_BaiduMap();
    } else if (mapType == 2) {
      window.FunList.clearanceMarkers_FMap();
    }
  }
}
/* @隐藏地图图标 */
function hideMapMarks(falg) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (mapType == 1) {} else if (mapType == 2) {
    window.FunList.hideMarkers_FMap(falg);
  }
}
/* @隐藏地图图标 */
function hideMapMarksText(falg) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (mapType == 1) {} else if (mapType == 2) {
    window.FunList.hiddenText_FMap(falg);
  }
}

/* @周边设备（弹窗） */
function drawPeriphery(locationMap, radius, data) {
  if (isCs(true)) {
    topVue.$Cs.ambitusLookup(locationMap, radius);
  } else {
    let mapType = localStorage.getItem("ilinkBs_currentMapType");
    if (mapType == 1) {
      window.FunList.periphery_BaiduMap(locationMap, radius, data);
    } else if (mapType == 2) {
      window.FunList.periphery_FMap(locationMap, radius, data);
    }
  }
}

/* @查看周边（工具包） */
function lookAround() {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (mapType == 1) {
    window.FunList.around_BaiduMap();
  } else if (mapType == 2) {
    window.FunList.lookAround_FMap();
  }
}

/* @调用地图导航 */
function navigationLocation(mapLocation) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  if (mapType == 1) {
    window.FunList.beginDrive_BaiduMap(0, mapLocation);
  } else if (mapType == 2) {
    window.FunList.Navigation_FMap();
  }
}
/* @初始化蜂鸟/百度地图热力图 */
function initDataHeatmap(data, maxValue) {
  if (isCs(true)) {
    // TODO 三维的热力图没做

  } else if (!topVue.bsConfig.MapOptions.svgMap) {
    let mapType = localStorage.getItem("ilinkBs_currentMapType");
    if (mapType == 1) {
      // 百度
      window.FunList.openHeatmap_BaiduMap(data, maxValue);
    } else if (mapType == 2) {
      window.FunList.showDataHeatmap_FMap(data, maxValue);
    }
  }
}
/* 切换音视频通话类型 
   2: 切换到视频通话
   1：切换到语意通话
*/
function changeCellType(type = 1) {
  if (isCs(true)) {
    topVue.$Cs.openRelatedPages(10106, "DialNumber", type.toString());
  } else {
    window.FunList.changeCellType(type);
  }
}

/**
 * @desc 关闭系统
 * @param
 */
function closeSystem() {
  closeDiscern();
  if (isCs()) {
    topVue.$Cs.closeSystem();
  } else {
    loading(1, 4000, "正在关闭系统...");
    logout({}).then(() => {
      let _platCode = localStorage.getItem("ilinkBs_platformCode");
      localStorage.removeItem("ilinkBs_sessionid");
      window.wsForBs ? window.wsForBs.close() : "";
      topVue.$router.push({
        path: "/login",
        query: _platCode !== "yxyljg" ? {
          loginId: _platCode
        } : {}
      });
    });
  }
}

/**
 * @desc Loading
 * @param {Boolean} startOrEnd
 * @param {Number} time
 */
let loadingInstance = null;

function loading(startOrEnd, time = 10 * 1000, text = "拼命加载中....") {
  if (isCs()) {
    //TODO  如果是三维，调用三维的加载方法
  } else {}
  if (startOrEnd) {
    loadingInstance = Loading.service({
      lock: true,
      text: text,
      spinner: "el-icon-loading",
      background: "rgba(0, 0, 0, 0.7)",
      customClass: "reset-loading" //Loading 的自定义类名
    });
    setTimeout(() => {
      loadingInstance.close();
    }, time);
  } else {
    loadingInstance ? loadingInstance.close() : "";
  }
}

/**
 * @desc message
 * @param {string} content
 * @param {string} type/success/warning/info/error
 */
function message(msg, type) {
  if (isCs(true)) {
    //TODO  如果是三维，调用三维的消息
  } else {}
  Message({
    message: msg || "提示",
    type: type || "warning",
    dangerouslyUseHTMLString: type == 3 ? true : false // 如果类型等于3，启用html片段
    // duration: 0
  });
}

/**
 * @desc 判断是否在c端
 * @param {Boolean} isIn3d 是否在c端且是三维地图
 */
function isCs(isIn3d) {
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  let inClient = localStorage.getItem("ilinkBs_inClient");
  return isIn3d ?
    mapType == 3 && inClient == 1 ?
    true :
    false :
    inClient == 0 ?
    false :
    inClient == null ?
    false :
    true;
}
/**
 * @desc 点击间隔 用法:if(getClickEnabel()){...}
 */
var _clickEnable;
var dfcpClickEnable = true;
// 获取点击事件许可
function getClickEnabel(showTips, times) {
  if (dfcpClickEnable) {
    setClickDisabled(times);
    return true;
  }
  if (showTips) {
    message("请勿频繁操作！", "warning");
  }
  return false;
}
// 设置不可用
function setClickDisabled(times) {
  dfcpClickEnable = false;
  if (_clickEnable != null) {
    clearTimeout(_clickEnable);
  }
  _clickEnable = null;
  _clickEnable = setTimeout(
    setClickEnable,
    times ? parseInt(800) * times : 800
  );
}
// 设置可用
function setClickEnable() {
  dfcpClickEnable = true;
}

/**
 * @desc 禁用f5、选中等
 */
function banF5andSelected() {
  let f5Check = function (e) {
    e = e || window.event;
    if ((e.which || e.keyCode) == 116) {
      if (e.preventDefault) {
        e.preventDefault();
      } else {
        event.keyCode = 0;
        e.returnValue = false;
      }
    }
  };
  if (document.addEventListener) {
    document.addEventListener("keydown", f5Check, false);
  } else {
    document.attachEvent("onkeydown", f5Check);
  }
  document.oncontextmenu = function (e) {
    return false;
  };
  document.onselectstart = function (e) {
    return false;
  };
}

function loadJsCss(filename, filetype) {
  if (filetype == "js") {
    var fileref = document.createElement("script"); //创建标签
    fileref.setAttribute("type", "text/javascript"); //定义属性type的值为text/javascript
    fileref.setAttribute("src", filename); //文件的地址
  } else if (filetype == "css") {
    var fileref = document.createElement("link");
    fileref.setAttribute("rel", "stylesheet");
    fileref.setAttribute("type", "text/css");
    fileref.setAttribute("href", filename);
  }
  if (typeof fileref != "undefined") {
    document.getElementsByTagName("head")[0].appendChild(fileref);
  }
}

/**
 * @desc 定义一个缩放函数，根据宽或者高其中一项低于阀值了，返回一个缩放比例
 * @param {Sting} url
 * @param {Sting} title
 * @param {Number} w
 * @param {Number} h
 */
function getScale(num, total, isparseInt) {
  if (window.screen.height > 1070) {
    $(".mainBody").addClass("bodyscale"); // 针对1024px高度自适应写得class
  } else {
    $(".mainBody").removeClass("bodyscale");
  }
}

/**
 * @desc 获取推送配置
 * @param {}
 */
function getPushConfig() {
  let isMuilUnitUser = topVue.$store.state.userInfo.isMuilUnitUser;
  let pushArr = localStorage.getItem("ilinkBs_pushConfig");
  pushArr
    ?
    (pushArr = JSON.parse(pushArr)) :
    (pushArr = isMuilUnitUser ? [{
        type: "401",
        name: "高危信号推送",
        switch: "1",
        Mute: "0"
      },
      {
        type: "402",
        name: "重大问题推送",
        switch: "1",
        Mute: "0"
      },
      {
        type: "403",
        name: "警情推送",
        switch: "1",
        Mute: "0"
      },
      {
        type: "404",
        name: "隐患推送",
        switch: "1",
        Mute: "0"
      },
      {
        type: "405",
        name: "推送跳转",
        switch: "1",
        Mute: "0"
      }
    ] : [{
        type: "403",
        name: "警情推送",
        switch: "1",
        Mute: "0"
      },
      {
        type: "404",
        name: "隐患推送",
        switch: "1",
        Mute: "0"
      },
      {
        type: "405",
        name: "推送跳转",
        switch: "1",
        Mute: "0"
      }
    ]);
  return pushArr;
}

/**
 * @desc 保存推送配置
 * @param {Array} dataArr
 *  [
        { 'type':'401','name':'高危信号推送','switch':'0','Mute':'0' },
        {  'type':'402','name':'重大问题推送','switch':'0','Mute':'1' },
        {  'type':'403','name':'警情推送','switch':'0','Mute':'1' },
        { 'type':'404','name':'隐患推送','switch':'0','Mute':'0' }
    ]
    type 配置类型
    name 配置名称
    switch 是否开启 0 未开启 1 开启
    Mute   是否静音 0 未开启 1 开启
 */
function setPushConfig(dataArr) {
  if (dataArr && Array.isArray(dataArr)) {
    localStorage.setItem("ilinkBs_pushConfig", JSON.stringify(dataArr));
  }
}

/*
 * 初始化页面伪路由记录
 */
function initRouteList() {
  let routeList = [{
    name: "Home"
  }];

  localStorage.setItem("ilinkBs_routeList", JSON.stringify(routeList));
  topVue.$store.commit('setSearchModelStatus', true)
}

/*
 * 页面有切换，记录伪路由
 * 【pageName】： 页面名称
 * 【parames】 ： 页面跳转附带参数
 */
function addRoutePage(pageName, parames) {
  let routeList = JSON.parse(localStorage.getItem("ilinkBs_routeList")) || [];
  let pageModel = {
    name: pageName,
    parames: parames
  };
  //如果当前模块和上一页模块是同一个模块，则覆盖更新
  if (
    routeList.length > 0 &&
    routeList[routeList.length - 1].name == pageModel.name
  ) {
    // 如果是同一页面不重复添加
    routeList[routeList.length - 1] = pageModel;
  } else {
    routeList.push(pageModel);
  }
  // 缓存记录中添加新路由
  localStorage.setItem("ilinkBs_routeList", JSON.stringify(routeList));
  topVue.$store.commit('setRouteList', routeList)
  // 这个地方不能用到some方法 因为伪路由会一直累加 只清除最后一项 所以要判断list最后一项是否为Maintenance
  // const res =  routeList.some(val => {
  //     return val.name === "Maintenance";
  // });
  const res = (routeList[routeList.length - 1].name === 'Maintenance' /* || routeList[routeList.length - 1].name ==='RectificationDangers' */ ) ? false : true
  topVue.$store.commit('setSearchModelStatus', res)
}

/*
 * 获取当前展示页面的路由名称
 */
function getCurrentPage() {
  let routeList = JSON.parse(localStorage.getItem("ilinkBs_routeList")) || [];
  let i = routeList.length - 1;
  if (i < 0) {
    return {
      name: "Home"
    };
  } else {
    return routeList[i];
  }
}

/*
 * 返回上一页
 * 【各页面模块名】
 * 首页：'Home'
 * 单单位首页：'SingleHome' (enterSingleHome)
 * 安全评估：'FireSafetyAssess' (enterDetail)
 * 高危信号: 'HighRiskSignal' (enterDetail)
 * 重大问题: 'ImportQuestion' (enterDetail)
 * 平台管理: 'PlatformManage' (enterDetail)
 * 呼叫中心: 'CellCenter' (enterDetail)
 * 接处警: 'ReceivingPolice' (enterChild)
 * 日常巡检: 'Inspection' (enterChild)
 * 隐患监管：'RectificationDangers' (enterChild)
 * 隐患清单：'HiddenDangers' (enterDetail)
 * 维保监管：'Maintenance' (enterChild)
 * 维保时间线：'MaintenanceTimeLine' (enterDetail)
 * 设备一张图：'MapEquipment' (enterChild)
 * 设备清单：'EquipmentList' (enterDetail)
 */
function backProvePage() {
  let routeList = JSON.parse(localStorage.getItem("ilinkBs_routeList")) || [];
  if (routeList.length > 1) {
    routeList.pop();
    // 上一页模块对象
    let pageObj = routeList[routeList.length - 1];
    // 根据模块名称跳转对应页面
    switch (pageObj.name) {
      case "FireSafetyAssess":
      case "HighRiskSignal":
      case "ImportQuestion":
      case "PlatformManage":
      case "HiddenDangers":
      case "AICloudVideo":
      case "MaintenanceTimeLine":
      case "EquipmentList":
        // 跳转全屏详情页的
        enterDetail(pageObj.name, pageObj.parames);
        break;
      case "ReceivingPolice":
      case "Inspection":
      case "RectificationDangers":
      case "Maintenance":
      case "MapEquipment":
      case "CellCenter":
        // 跳转左右结构的页面
        enterChild(pageObj.name, {
          ...pageObj.parames,
          isRefresh: true
        });
        break;
      case "SingleHome":
        // 单单位首页
        enterSingleHome({
          orgId: localStorage.getItem("ilinkBs_orgIds")
        });
        break;
      default:
        // 默认返回首页
        backHome();
        break;
    }
  } else {
    routeList = [{
      name: "home"
    }];
    // 默认返回首页
    backHome('', true);
  }
  // 更新缓存记录中的路由
  localStorage.setItem("ilinkBs_routeList", JSON.stringify(routeList));
  // const res =  routeList.some(val => {
  //     return val.name === "Maintenance";
  // });
  const res = (routeList[routeList.length - 1].name === 'Maintenance' /* || routeList[routeList.length - 1].name ==='RectificationDangers' */ ) ? false : true
  topVue.$store.commit('setSearchModelStatus', res)
}

/*
 * 三维场景中，切换左中右页面容器大小,在大分辨率的设备上，右侧首页平铺
 * pageType 2: 首页  1：左右子页
 */
function changePageSize(pageType = 1) {
  let maxW = 600; //单列最佳展示效果区间
  let minW = 480; //单列最佳展示效果区间
  let windowWidth = isCs() ?
    localStorage.getItem("ilinkBs_windowWidth") :
    window.document.body.clientWidth;
  let _bsConfig = topVue.bsConfig;
  let widper_l = parseFloat(_bsConfig.LeftMenu.width) / 100;
  let widper_r = parseFloat(_bsConfig.RightMenu.width) / 100;
  let cardNum_r =
    _bsConfig.RightMenu.cards2 && _bsConfig.RightMenu.cards2.length > 0 ?
    2 :
    1;
  if (windowWidth * widper_l > maxW) {
    widper_l = (maxW * 100) / windowWidth + "%";
  } else if (windowWidth * widper_l < minW) {
    widper_l = (minW * 100) / windowWidth + "%";
  } else {
    widper_l = widper_l * 100 + "%";
  }
  let carouselFlag = 2; //2 轮播  1 平铺 0 只有一页
  if (pageType == 2 && cardNum_r == 2) {
    //有2组卡片的首页右侧
    // widper_l = (minW * 100) / windowWidth + "%";
    if (windowWidth * widper_r > 2 * maxW) {
      widper_r = (2 * maxW * 100) / windowWidth + "%";
      carouselFlag = 1;
    } else if (
      windowWidth * widper_r > 1.5 * minW &&
      windowWidth * widper_r <= 2 * maxW
    ) {
      widper_r = (2 * minW * 100) / windowWidth + "%";
      carouselFlag = 1;
    } else if (
      windowWidth * widper_r > maxW &&
      windowWidth * widper_r <= 1.5 * minW
    ) {
      widper_r = widper_r * 100 + "%";
    } else {
      widper_r = (minW * 100) / windowWidth + "%";
    }
  } else {
    if (windowWidth * widper_r > maxW) {
      widper_r = (maxW * 100) / windowWidth + "%";
    } else if (windowWidth * widper_r < minW) {
      widper_r = (minW * 100) / windowWidth + "%";
    } else {
      widper_r = widper_r * 100 + "%";
    }
    if (pageType == 2 && cardNum_r == 1) {
      carouselFlag = 0;
    }
  }
  localStorage.setItem("ilinkBs_carouselFlag", carouselFlag);

  if (isCs(true)) {
    //各个容器
    let pageBox = [{
        type: "10400", //首页地图
        length: parseFloat(_bsConfig.MapOptions.height) / 100,
        wide: parseFloat(_bsConfig.MapOptions.width) / 100
      },
      {
        type: "10401", //多/单位左
        length: 1,
        wide: 1 * (parseFloat(widper_l) / 100).toFixed(2)
      },
      {
        type: "10402", //多/单位右
        length: 1,
        wide: 1 * (parseFloat(widper_r) / 100).toFixed(2)
      }
    ];
    topVue.$Cs.pageSetup(JSON.stringify(pageBox));
  } else {
    window.FunList.changeLeftRightSize &&
      window.FunList.changeLeftRightSize({
        leftWidth: widper_l,
        rightWidth: widper_r
      });
    //topVue.bsConfig.LeftMenu.width = widper_l
  }
}

/*
 * 定位呼叫人员再地图中的位置
 * positionInfo 位置信息
 * personInfo 人员信息
 *  【例如】
 *  positionInfo：'{"lat": 31.82554, "lon": 177.131}'
 *  personInfo： {"name":"张亚","accountName":"zya","headUrl":null}
 */
function locateCallee(positionInfo, personInfo) {
  try {
    positionInfo = JSON.parse(positionInfo);
  } catch (e) {
    message("暂无通话人员定位！", "warning");
    return;
  }
  let mapType = localStorage.getItem("ilinkBs_currentMapType");
  let headUrl = personInfo.headUrl || globalVariable.defultMapPeople;
  if (isCs(true)) {
    let yingyanLonLat = transWGS.bd09_to_gcj02_to_wgs84(
      positionInfo.lon,
      positionInfo.lat
    );
    let position3d = {
      lon: yingyanLonLat[0],
      lat: yingyanLonLat[1],
      alt: 0,
      rotateX: 0,
      rotateY: 0,
      rotateZ: 0,
      zoomX: 0,
      zoomY: 0,
      zoomZ: 0,
      objProp: null,
      viewLon: 0,
      viewLat: 0,
      viewAlt: 0,
      viewTilt: 0,
      viewHeading: 0
    };
    topVue.$Cs.callLocation(JSON.stringify(position3d), headUrl);
  } else {
    if (mapType == 1) {
      window.FunList.addCallmarker_BaiduMap(positionInfo, headUrl);
    } else if (mapType == 2) {
      window.FunList.addCallMarker_FMap(1, headUrl);
    }
  }
}

export default {
  enterSingleHome,
  enterSingleUnitMap,
  backHome,
  getScale,
  banF5andSelected,
  loadJsCss,
  enterChild,
  openPopup,
  closePopup,
  enterDetail,
  switchMapType,
  closeSystem,
  loading,
  isCs,
  getClickEnabel,
  message,
  setMapOptions,
  intMapMarks,
  getPushConfig,
  setPushConfig,
  voiceCmd,
  fixedPosition,
  fixedPosition_fc,
  changeThemeMap,
  tranficStatus,
  openPanoramaWind,
  setMapMark,
  closeAudioDisposeCtl,
  closeDiscern,
  setAudioDisposeCtl,
  excuteCmdResult,
  setDiscernResultCtl,
  openPushAudioCtl,
  excuteAudioCmdCtl,
  distanceMeasure,
  highMeasure,
  clearMapMark,
  changeMode23D,
  lookAround,
  adjustSpacing,
  hideMapMarks,
  hideMapMarksText,
  getVideoDetail,
  showVideoClient,
  drawPeriphery,
  refreshMapMarkerDataToFmap,
  init_webSocket,
  getPushData,
  pushMapMark,
  navigationLocation,
  initRouteList,
  addRoutePage,
  getCurrentPage,
  backProvePage,
  changePageSize,
  resizeCharts,
  changeCellType,
  locateCallee,
  initDataHeatmap
};
